import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'

// 使用代理转发到后端网关，避免 CORS 问题
export default defineConfig({
  plugins: [uni()],
  server: {
    host: '0.0.0.0',
    port: 5173,
    strictPort: false,
    // 允许访问到不安全端口
    cors: true,
    proxy: {
		//http://8.145.55.161:5173/
      // 用户服务路由 - 根据Nacos配置，网关会将/user/**路由到user-service
      '/user': {
        target: 'http://8.145.55.161:8000', // 网关地址
        changeOrigin: true,
        secure: false
      },
      '/product': {
        target: 'http://8.145.55.161:8000',
        changeOrigin: true,
        secure: false
      },
      '/cart': {
        target: 'http://8.145.55.161:8000',
        changeOrigin: true,
        secure: false
      },
      '/order': {
        target: 'http://8.145.55.161:8000',
        changeOrigin: true,
        secure: false
      },
      '/orders': {
        target: 'http://8.145.55.161:8000',
        changeOrigin: true,
        secure: false
      },
      // AI服务路由 - 通过网关代理
      '/ai': {
        target: 'http://8.145.55.161:8000', // 网关地址
        changeOrigin: true,
        secure: false
      },
      // AI服务器直接路由 - 用于AI对话功能
      '/aiserver': {
        target: 'http://8.145.55.161:8000', // 网关地址
        changeOrigin: true,
        secure: false
      }
    }
  }
})